
import { StateNode } from "@/core/effect";
import {DataSourceMgr,ChartConfigMgr,ChartIdMap,effect,IRadarChartConfig,IRadarChartOptions} from "@/index"

function random(min:number, max:number) {
    return Math.floor(Math.random() * (max - min)) + min;
}
export default function(
    chartTarget?:ChartConfigMgr<IRadarChartConfig>,
    dataSource?:DataSourceMgr,
    reRender?:()=>void,
    destroyMySelf?:()=>void
    ){
        if(!dataSource)
            throw new Error("component4数据源初始化失败！");
        const indicatorState = dataSource?.useState<Array<{name:string,max:number}>>([]);
        let seriesStates = new Array<StateNode<Array<number>>>();
        const container = document.getElementById(chartTarget?.getConfig("container"));
        const myChartTarget = (<any>window).echarts.init(container);
        let myOptions = <IRadarChartOptions>chartTarget?.getConfig("ChartOptions") || {};
        myOptions.series.forEach(conf => {
            seriesStates.push(dataSource?.useState<Array<number>>([]));
        });
        // const currentDatas = myOptions.series;
        effect(()=>{
            myOptions = <IRadarChartOptions>chartTarget?.getConfig("ChartOptions") || {};
            myChartTarget.setOption(myOptions);
        },[chartTarget]);
        // effect(()=>{
        //     myChartTarget.setOption({
        //         series: newDatas
        //     });
        // },[indicatorState,...seriesStates])
        // effect(()=>{
        //     // innerSpan.innerHTML = chartTarget?.getConfig("title")||"空空如也";
        // },[chartTarget]);

        //effect(()=>{
            // let newSerise = currentDatas.map(current=>{
            //     current.data = current.data.map((data,index)=>{
            //         return {
            //             value: new Array(6).fill(random(1000,10000)),
            //             name: ['Allocated Budget','Actual Spending'][index]
            //         }
            //     });
            //     return {...current};
            // })
        //     myChartTarget.setOption({
        //         radar:{indicator:indicatorState},
        //         series: seriesStates.map((serise,index)=>{
        //             return {
        //                 value:serise.value,
        //                 name:myOptions.legend.data[index]
        //             }
        //         })
        //     });
        // },[indicatorState,...seriesStates]);
}